package com.liy.framework.common.thread;

import org.springframework.scheduling.annotation.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.scheduling.concurrent.*;
import java.util.concurrent.*;
import org.springframework.context.annotation.*;

@Configuration
@EnableAsync
public class TaskExecutePool
{
    @Autowired
    private TaskThreadPoolConfig config;
    
    @Bean(name = { "threadPoolTaskExecutor" })
    public Executor myTaskAsyncPool() {
        final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(this.config.getCorePoolSize());
        executor.setMaxPoolSize(this.config.getMaxPoolSize());
        executor.setQueueCapacity(this.config.getQueueCapacity());
        executor.setKeepAliveSeconds(this.config.getKeepAliveSeconds());
        executor.setThreadNamePrefix("Das-Executor-");
        executor.setRejectedExecutionHandler((RejectedExecutionHandler)new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return (Executor)executor;
    }
}
